﻿using System;
using System.Collections.Generic;
using System.IO;
using log4net.Config;
using NFreeMarker.Cache;
using NFreeMarker.Template;

namespace NFreeMarker.TestProgram
{
    internal static class Program
    {
        private static void Main()
        {
            BasicConfigurator.Configure();

            var stringTemplateLoader = new StringTemplateLoader();
            stringTemplateLoader.PutTemplate("test.ftl", "${user}");

            var cfg = new Configuration();
            cfg.LoadBuiltInEncodingMap();
            cfg.SetObjectWrapper(new DefaultObjectWrapper());
            cfg.SetTemplateLoader(stringTemplateLoader);

            Template.Template temp = cfg.GetTemplate("test.ftl");

            var latest = new Dictionary<string, string>
            {
                {"url", "products/greenmouse.html"},
                {"name", "green mouse"}
            };
            var root = new Dictionary<string, object>
            {
                {"user", "Big Joe"},
                {"latestProduct", latest}
            };

            using (TextWriter writer = Console.Out)
            {
                try
                {
                    temp.Process(root, writer);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Oops.");
                }
            }
        }
    }
}